package com.baidu.service.impl;

import com.baidu.model.entity.MarkModel;
import com.baidu.model.entity.example.MarkModelExample;
import com.baidu.model.mapper.MarkModelMapper;
import com.baidu.service.InMarkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.until.pagination.PaginationRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author user
 */
@Service
public class MarkServiceImpl implements InMarkService {
    @Autowired
    private MarkModelMapper markModelMapper;

    @Override
    public int createMark(MarkModel markModel) throws Exception {
        return markModelMapper.insertSelective(markModel);
    }

    @Override
    public PageInfo<MarkModel> selectMarkByPhotoId(PaginationRequest paginationRequest, Integer id) {
        MarkModelExample markModelExample = new MarkModelExample();
        markModelExample.createCriteria().andPhotoIdEqualTo(id);
        return PageHelper.startPage(paginationRequest.getPageNumber(), paginationRequest.getPageSize()).doSelectPageInfo(() ->
                markModelMapper.selectByExample(markModelExample));
    }

    @Override
    public int updateMarkById(MarkModel markModel) throws Exception {
        return markModelMapper.updateByPrimaryKeySelective(markModel);
    }

    @Override
    public int deleteMarkById(Integer id) throws Exception {
        return markModelMapper.deleteByPrimaryKey(id);
    }
}
